/**
 * 
 */
package org.karthik.ecomm.dto;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Table;

import org.hibernate.annotations.CollectionId;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;

/**
 * @author Uday Shankar
 * 
 */
@Entity
@Table(name = "CUSTOMER")
public class Customer {
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "CUSTOMER_ID")
	private int customerID;
	@Column(name = "CUSTOMER_NAME")
	private String customerName;

	// CustomerMain class will give a laxyInitializationException if fetchType
	// is changed to LAZY(default is LAZY)

	@ElementCollection(fetch = FetchType.EAGER)
	@JoinTable(name = "CUSTOMER_PRODUCTS", joinColumns = @JoinColumn(name = "CUSTOMER_ID"))
	@GenericGenerator(name = "hilo-gen", strategy = "hilo")
	@CollectionId(columns = { @Column(name = "CUSTOMER_PRODUCT_INDEX") }, generator = "hilo-gen", type = @Type(type = "long"))
	private Collection<Product> listOfProducts = new ArrayList<Product>();

	/* private Set<Product> listOfProducts = new HashSet<Product>(); */
	/**
	 * @return the customerID
	 */
	public int getCustomerID() {
		return customerID;
	}

	/**
	 * @param customerID
	 *            the customerID to set
	 */
	public void setCustomerID(int customerID) {
		this.customerID = customerID;
	}

	/**
	 * @return the customerName
	 */
	public String getCustomerName() {
		return customerName;
	}

	/**
	 * @param customerName
	 *            the customerName to set
	 */
	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	/**
	 * @return the listOfProducts
	 */
	public Collection<Product> getListOfProducts() {
		return listOfProducts;
	}

	/**
	 * @param listOfProducts
	 *            the listOfProducts to set
	 */
	public void setListOfProducts(Collection<Product> listOfProducts) {
		this.listOfProducts = listOfProducts;
	}

}
